﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace WebApplication13
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        public int folderSize;
        public int hardSize;
        public enum UnitType { KB = 1, MB = 2, GB = 3 }
        protected void Page_Load(object sender, EventArgs e)
        {
            Server.MapPath("~");
            folderSize=Convert.ToInt32(FindFolderSize(new DirectoryInfo(Server.MapPath("\\")), UnitType.MB, 2));
            hardSize = 2000-folderSize;

        }
        public double FindFolderSize(DirectoryInfo d, UnitType u, int r)
        {
            double divider = Math.Pow(1024, (int)u);
            double size = 0;
            foreach (FileInfo f in d.GetFiles())
                size += Convert.ToDouble(f.Length) / divider;
            foreach (DirectoryInfo c in d.GetDirectories())
                size += this.FindFolderSize(c, u, r);
            return Math.Round(size, r);
        }
    }
}